package com.hzy.quetosys.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzy.quetosys.dao.CustomerMapper;
import com.hzy.quetosys.dao.OrderMapper;
import com.hzy.quetosys.entity.Customer;
import com.hzy.quetosys.entity.Order;
import com.hzy.quetosys.service.CustomerService;
import com.hzy.quetosys.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Transactional(rollbackFor =Exception.class)
    @Override
    public boolean append(Order order) {
        return orderMapper.insert(order) > 0;
    }
    @Override
    public PageInfo<Order> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<Order> orders=orderMapper.selectByKeyword(keyword);
        PageInfo<Order> pageInfo=new PageInfo<>(orders);
        return pageInfo;
    }

    @Override
    public Order findById(int id) {
        return orderMapper.selectById(id);
    }

    @Transactional(rollbackFor =Exception.class)
    @Override
    public boolean modify(Order order) {
        return orderMapper.updateById(order)>0;
    }

    @Transactional(rollbackFor =Exception.class)
    @Override
    public boolean remove(int id) {
        return orderMapper.deleteById(id)>0;
    }
}
